<?
require_once('ValidatorBase.php');

class DateRangeValidator extends ValidatorBase {
	private $min,$max;

	// ACCESSORS
	public function setMin(DateTime $value) { $this->min= $value; return $this; }
	public function getMin() { return $this->min; }
	private function validateMin(DateTime $date) {
		if (is_null($this->min)) return true;
		return $date->format('YmdHis')>= $this->min->format('YmdHis');
	}

	public function setMax(DateTime $value) { $this->max= $value; return $this; }
	public function getMax() { return $this->max; }
	private function validateMax(DateTime $date) {
		if (is_null($this->max)) return true;
		return $date->format('YmdHis')<= $this->max->format('YmdHis');
	}

	protected function doValidate($value) {
		if (
			!$value instanceof DateTime ||
			!$this->validateMin($value) ||
			!$this->validateMax($value)
		) {
			throw new ValidatorException($this,$value);
		}
	}
}
